package wine.logic.interfaces;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;

import wine.ejb.utilities.BaseSessionBean;
import wine.ejb.utilities.PageInfo;
import wine.ejb.utilities.PagedResults;
import wine.ejb.utilities.Utility;
import wine.logic.bean.JviewInformationDao;
import wine.logic.entity.JviewInformation;
import wine.logic.entity.WUsrInf;

@Stateless
@Remote(JviewInformationDao.class)
@Local(JviewInformationDao.class)
public class JviewInformationImpl extends BaseSessionBean<JviewInformation> implements JviewInformationDao{
	
	public PagedResults<JviewInformation> findLstByModule(PageInfo pageInfo,String moduleName){
		StringBuffer ejbql = new StringBuffer(" from JviewInformation where 1=1 ");
		Map<String, Object> params = new HashMap<String, Object>();
		if(Utility.isNotEmpty(moduleName)){
			ejbql.append(" and smodulename = :smodulename");
			params.put("smodulename", moduleName);
		}
		ejbql.append(" order by idx desc,dpubdate desc,iinfoid");
		PagedResults<JviewInformation> pages = findListByEJBQL(ejbql.toString(), pageInfo, params);
		return pages;
	}
	public PagedResults<JviewInformation> findViewLst(PageInfo pageInfo, String searTitle, String searModulename,
			String searUserName,Date beginDate,Date endDate, String isok, String sifpic, WUsrInf usrInf){
		StringBuffer ejbql = new StringBuffer(" from JviewInformation where 1=1 ");
		Map<String, Object> params = new HashMap<String, Object>();
		if(Utility.isNotEmpty(searTitle)){
			ejbql.append(" and sinfotitle like :sinfotitle ");
			params.put("sinfotitle", "%"+searTitle.trim()+"%");
		}
		if(Utility.isNotEmpty(searModulename)){
			ejbql.append(" and smodulename like :smodulename ");
			params.put("smodulename", "%"+searModulename.trim()+"%");
		}
		if(Utility.isNotEmpty(searUserName)){
			ejbql.append(" and userName like :userName ");
			params.put("userName", "%"+searUserName.trim()+"%");
		}
		if(Utility.isNotEmpty(beginDate)){
			ejbql.append(" and dpubdate >= :beginDate");
			params.put("beginDate", beginDate);
		}
		if(Utility.isNotEmpty(endDate)){
			ejbql.append(" and dpubdate <= :endDate");
			params.put("endDate", endDate);
		}
		if(Utility.isNotEmpty(isok)){
			ejbql.append(" and isok = :isok");
			params.put("isok", isok);
		}
		if(Utility.isNotEmpty(sifpic)){
			ejbql.append(" and sifpic=:sifpic");
			params.put("sifpic", sifpic);
		}
		
		ejbql.append(" order by idx desc,dpubdate desc,iinfoid ");
		return super.findListByEJBQL(ejbql.toString(), pageInfo, params);
	}
	
	public JviewInformation findObjByIinfoid(Long iinfoid){
		try {
			Object obj=em.createNamedQuery("findObjbyPk").setParameter("iinfoid", iinfoid).getSingleResult();
			if(obj!=null){
				return (JviewInformation)obj;
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		return null;
	}
}
